package com.netty.collection;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.junit.Test;

import com.netty.entity.EntityType;
import com.netty.entity.MethodType;

public class EntityContainer {
	
	static Map<String,EntityType> serviceContainer = new ConcurrentHashMap<String,EntityType>();
	
	public static EntityContainer getInstance(){
		return new EntityContainer();
	}
	
	public void add(String name, Object cla){
		EntityType entityType = new EntityType();
		entityType.setClassMap(name);
		entityType.setFieldMap(null);
		entityType.setObj(cla);
		serviceContainer.put(name, entityType);
	}
	
	public void addField(String name, Map<String,MethodType> fieldMap){
		EntityType entityType = serviceContainer.get(name);
		entityType.setFieldMap(fieldMap);
	}
	
	public EntityType get(String name){
		return serviceContainer.get(name);
	}
	
	public String hashName(String path){
		Set<String> sets = serviceContainer.keySet();
		String matchPath = path.substring(0,path.substring(1).indexOf("/")+1);
		if(sets.contains(matchPath)){
			return matchPath;
		}
		return null;
	}
	
	@Test
	public void test(){
		String path = "/test/asdasd/asdasd";
		String calssName = "/test";
//		String matchPath = path.substring(0,path.substring(1).indexOf("/")+1);
		String matchPath = path.replaceAll(calssName, "");
		System.out.println(matchPath);
	}
}
